package com.class05.dao.impl;

import com.class05.dao.StudentDao;
import com.class05.pojo.Student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class StudentDaoImpl implements StudentDao {
    private JdbcTemplate jdbcTemplate;

    //    注入我们的jdbcTemplate对象
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Student> queryAll() {
        String sql = "select id , name , gender , age , " +
                "class as classes from students ;";
        //        BeanPropertyRowMapper帮我们自动映射列和属性值！
        //        要求列名和属性名一致！
        //         不一致   起别名！
        List<Student> students = jdbcTemplate.
                query(sql, new BeanPropertyRowMapper<Student>(Student.class));
        System.out.println("studentDao:" + students);
        return students;
    }
}
